﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SimpleHttpFramework {
    public class Router {
        private readonly Dictionary<string, Controller.ControllerMethod> _routerTable;

        public Router()
        {
            this._routerTable = new Dictionary<string, Controller.ControllerMethod>();

            this.Register("/", Controller.Index);
        }

        public Controller.ControllerMethod this[string index] =>
            this._routerTable.ContainsKey(index) ? this._routerTable[index] : null;

        public void Register(string url, Controller.ControllerMethod method)
        {
            if (!this._routerTable.ContainsKey(url))
                this._routerTable.Add(url, method);
            else
                this._routerTable[url] = method;
        }

        public bool ContainsUrl(string url) => this._routerTable.ContainsKey(url);
    }
}